//
//  RegViewController.m
//  TT
//
//  Created by lanou3g on 16/3/11.
//  Copyright © 2016年 Super磊. All rights reserved.
//

#import "RegViewController.h"
#import <AVOSCloud/AVOSCloud.h>
#import "DetailRegViewController.h"
@interface RegViewController ()
@property (weak, nonatomic) IBOutlet UITextField *txtuserPhoneNum;
@property (weak, nonatomic) IBOutlet UITextField *txtSms;
@property (weak, nonatomic) IBOutlet UITextField *userName;
@property (weak, nonatomic) IBOutlet UITextField *userPassWord;
@property (weak, nonatomic) IBOutlet UIButton *Change;
@end

@implementation RegViewController

- (void)viewDidLoad {
    [super viewDidLoad];

     [AVOSCloud setApplicationId:@"pLGUE2TepdIMn4pfjc9UOogY-gzGzoHsz" clientKey:@"Issl3J2BacCnbCCSk99vqs3K"];
    self.view.backgroundColor =[UIColor lightGrayColor];
    self.title =@"手机号码注册";
    //监听改变量
    self.Change.enabled =NO;
    [self.Change setBackgroundImage:nil forState:(UIControlStateDisabled)];
    [self.Change setBackgroundImage:nil forState:(UIControlStateNormal)];
    //bar
    UIBarButtonItem *item =[[UIBarButtonItem alloc]initWithTitle:@"下一步" style:(UIBarButtonItemStyleDone) target:self action:@selector(itemAction)];
    self.navigationItem.rightBarButtonItem =item;
    
}

#pragma mark - 获取短信验证码
- (IBAction)smsTesting:(id)sender {
    AVUser *user =[AVUser user];
    user.mobilePhoneNumber =self.txtuserPhoneNum.text;
    user.password =self.userPassWord.text;
    user.username =self.userName.text;
    [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        NSLog(@"%@",self.txtuserPhoneNum.text);
        if (succeeded) {
            
            NSLog(@"成功");
        }else {
        
            NSLog(@"%@",error);
        }
    
    }];
}
-(void)itemAction {
    
    DetailRegViewController *detail =[DetailRegViewController new];
    detail.mobilePhoneNumber = self.txtuserPhoneNum.text;
    [AVUser verifyMobilePhone:self.txtSms.text withBlock:^(BOOL succeeded, NSError *error) {
        if (error) {
            NSLog(@"%@",error);
        }
        else {
            [self.navigationController pushViewController:detail animated:YES];
        }
    }];
    
    
    
    
}
//用户名的监听状态(textFild框的EditingChange)
- (IBAction)EdChange:(id)sender {
    NSLog(@"1");
    if (self.txtuserPhoneNum.text.length == 11) {
        self.Change.enabled =YES;
    }else {
        self.Change.enabled =NO;
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
